package com.itheima.tlias.tliasweb.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class DemoInterceptor implements HandlerInterceptor {


    /**
     * 业务方法执行前调用，
     * @return 如果是true，继续执行业务逻辑，如果是false，不执行业务逻辑
     * */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        log.info("----->DemoInterceptor  preHandle ");
        return true;
    }

    /**
     * 业务方法执行完成以后，前提是业务方法不能出异常
     *
     * */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("----->DemoInterceptor  postHandle ");
    }

    /**
     * 业务方法执行完成以后，更靠后，在postHandle的后边，不管业务方法是否抛出异常
     *
     * */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info("----->DemoInterceptor  afterCompletion ");
    }
}
